import {login} from '@/api/login'
import axios from 'axios'
import request from '@/utils/request'

const user = {
  state: {
    name: '',
    count: 0
  },
  mutations: {

  },
  actions: {
    Login({commit},userInfo) {
      const username = userInfo.username.trim();
      axios({
        method: 'post',
        url: 'https://www.easy-mock.com/mock/5b0e0bc19a9dc61094244547/today/user/login',
        data: {
          firstName: 'Fred',
          lastName: 'Flintstone'
        }
      }).then(value => {
        console.log(value.data)
        return value
      }).catch(error => {
        console.log('报错')
      })
      /*return new Promise((reslove,reject) => {
        console.log('promise...')
        console.log(userInfo.password)
        login(username,userInfo.password).then(response => {
          console.log(response.data)
        }).catch(error => {
          console.log(error)
        })
      })*/
      /*request({
        url: '/user/login',
        method: 'post',
        data: {
        }
      }).then(value => {
        console.log('request.error')
      }).catch(error => {
        console.log('error -- error')
      })*/
    }
  },
  getters: {
    count: state => state.count,
    name: state => state.name
  }
}

export default user
